<template>
  <el-cascader
    :value="value"
    :options="options"
    size="mini"
    :props="props"
    separator="-"
    @change="handleChange"
  />
</template>

<script>
import { getDepartment } from '@/api/department'
import { transListToTree } from '@/utils'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      options: [],
      props: {
        label: 'name',
        value: 'id'
      }
    }
  },
  created() {
    this.getDepartmentList()
  },
  methods: {
    handleChange(value) {
      if (value.length) {
        this.$emit('input', value.at(-1))
      }
    },
    async getDepartmentList() {
      const res = await getDepartment()
      this.options = transListToTree(res, 0)
    }
  }
}
</script>

<style>

</style>
